##################################################################
# File : /lua/ui/network/loginclient.lua
# Description : Dark Skies networking module
# Author : Neruz
##################################################################

local internalComm = import('/lua/ui/network/lobbycomm.lua')

LoginClient = Class(internalComm.LobbyComm) {
	
	ConnectionFailed = function(self, reason)
		internalComm.LobbyComm.ConnectionFailed(self, reason)
	end,

	ConnectionToHostEstablished = function(self, localId, localName, hostId)
		internalComm.LobbyComm.ConnectionToHostEstablished(self, localId, localName, hostId)
	end,

	RequestLogin = function(self, accountName, password)
		self:SendData(0, {_type = "RequestLogin", login = { accountName = accountName, passwordHash = string.hash(password)}})
	end,
	
	RequestRegistration = function(self, accountName, password, email)
		self:SendData(0, {_type = "RegisterAccount", registration = { accountName = accountName, email = email, passwordHash = string.hash(password)}})
	end,
	
	DataReceived = function(self, data)

	end,

	JoinGame = function(self, addr, remotePlayerName, remotePlayerUID)
		internalComm.LobbyComm.JoinGame(self, addr, remotePlayerName, remotePlayerUID)
	end,
}

function InitLoginClient(protocol)
    local comm = LoginClient(protocol, 0, internalComm.maxConnections, "loginClient", nil, nil)
    return comm
end
